package com.zhss.designpattern.template;

public class TemplateMethodPatterDemo {

    public static void main(String[] args) {
        AbstractDiscountCalculator calculator1 = new DiscountCalculator1();
        AbstractDiscountCalculator calculator2 = new DiscountCalculator2();
        AbstractDiscountCalculator calculator3 = new DiscountCalculator3();

        calculator1.calculate();
        calculator2.calculate();
        calculator3.calculate();

    }

    interface DiscountCalculator{
        void calculate();
    }

    public static abstract class AbstractDiscountCalculator implements DiscountCalculator {
        public void calculate(){
            // 完成通用的计算逻辑
            commonCalculate();

            // 完成特殊的计算逻辑
            specificCalculate();
        }
            private void commonCalculate(){
                System.out.println("-----公共方法----");
            }

            abstract void specificCalculate();
    }

    static class DiscountCalculator1 extends AbstractDiscountCalculator{
        @Override
        void specificCalculate() {
            System.out.println("特殊1执行方法。。。。。。。。。");
        }
    }

    static class DiscountCalculator2 extends AbstractDiscountCalculator{
        @Override
        void specificCalculate() {
            System.out.println("特殊2执行方法。。。。。。。。。");
        }
    }

    static class DiscountCalculator3 extends AbstractDiscountCalculator{
        @Override
        void specificCalculate() {
            System.out.println("特殊3执行方法。。。。。。。。。");
        }
    }
}
